{% block editor_content %}
<div id='view_content'></div>
<div style="display:none">
	<form action="" method="post" id="myForm">
	  {{ form.content }}
	</form>
</div>

<script type="text/javascript">
function doSave(){
	var oEditor = FCKeditorAPI.GetInstance('id_content');
	new Ajax.Request('.', {
		parameters: {content:oEditor.GetData()},
		method: 'post',
	  	onSuccess: function(transport) {
	  }
	});
	oEditor.EditorWindow.parent.FCKToolbarItems.LoadedItems['Save'].Disable();
    return false; //this disables default action (submitting the form)
}

function enableSave(editorInstance) {
	editorInstance.EditorWindow.parent.FCKToolbarItems.LoadedItems['Save'].Enable()
}

function FCKeditor_OnComplete( editorInstance ){
	editorInstance.LinkedField.form.onsubmit = doSave;
	editorInstance.Events.AttachEvent('OnSelectionChange', enableSave);

	// Get the Editor Area DOM (Document object)
	var oEditor = editorInstance;
	var oDOM = oEditor.EditorDocument ;

	if ( document.all ) {
		// If Internet Explorer
		oDOM.attachEvent("onkeydown",keydownHandler)
	}
	else {
		oDOM.addEventListener("keydown",keydownHandler,false);
	}
}

function keydownHandler(ev) {
	if (ev.ctrlKey && (ev.keyCode == 83)) {
		//alert("ev.type= " + ev.type + " ev.keyCode= " + ev.keyCode + " ev.ctrlKey= " + ev.ctrlKey);
		// Event is from prototype.js
		Event.stop(ev);
		doSave();
	}
}

</script>

<script type="text/javascript">
	var oFCKeditor = new FCKeditor('id_content');
	oFCKeditor.BasePath = "/fckeditor/";
	// need detect the current height of the window
	var autoHeight = document.documentElement.clientHeight - 80;
	if (autoHeight < 400)
		autoHeigh = 400;
	oFCKeditor.Height = autoHeight;
	oFCKeditor.Create();
</script>

{% endblock %}